package jobs.model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import jobs.pattern.structural.EntityDecorator;

/**
 *
 * @author Paul Tamayo
 */
@Entity
@Table(name = "graduate")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Graduate.findAll", query = "SELECT g FROM Graduate g"),
    @NamedQuery(name = "Graduate.findById", query = "SELECT g FROM Graduate g WHERE g.id = :id"),
    @NamedQuery(name = "Graduate.findByName", query = "SELECT g FROM Graduate g WHERE g.name = :name"),
    @NamedQuery(name = "Graduate.findByDescription", query = "SELECT g FROM Graduate g WHERE g.description = :description")})
public class Graduate implements Serializable, EntityDecorator {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 150)
    @Column(name = "name")
    private String name;
    @Size(max = 200)
    @Column(name = "description")
    private String description;
    @ManyToMany(mappedBy = "graduateCollection")
    private Collection<FormalInstruction> formalInstructionCollection;

    public Graduate() {
    }

    public Graduate(Integer id) {
        this.id = id;
    }

    public Graduate(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public Integer getId() {
        return id;
    }

    @Override
    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @XmlTransient
    public Collection<FormalInstruction> getFormalInstructionCollection() {
        return formalInstructionCollection;
    }

    public void setFormalInstructionCollection(Collection<FormalInstruction> formalInstructionCollection) {
        this.formalInstructionCollection = formalInstructionCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Graduate)) {
            return false;
        }
        Graduate other = (Graduate) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return name;
    }

    @Override
    public String getEntityName() {
        return "Posgrado";
    }
}
